import sys
import os


def restart_myself():
    python = sys.executable
    os.execl(python, python, *sys.argv)


def restart_custom(self, filename):
    try:
        filesize = os.path.getsize(filename)
        if filesize == 0:
            return None
        else:
            with open(filename, "rb") as fp:
                offset = -8
                while -offset < filesize:
                    fp.seek(offset, 2)
                    lines = fp.readlines()
                    if len(lines) >= 2:
                        return lines[-1]
                    else:
                        offset *= 2
                fp.seek(0)
                lines = fp.readlines()
                return lines[-1]
    except FileNotFoundError:
        print(filename + 'is not found!Please reenter the file name!')
        return None
